# Contributor: rubicon <rubicon@mailo.com>
# Maintainer:
pkgname=ocaml-lwd
_pkgname=nottui-lwt
pkgver=0.2
pkgrel=0
pkgdesc="Lightweight reactive documents"
url="https://github.com/let-def/lwd"
arch="all !riscv64" # restricted by ocaml
license="MIT"
depends="ocaml-runtime"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	dune
	ocaml
	ocaml-bigarray-compat-dev
	ocaml-compiler-libs
	ocaml-cppo
	ocaml-findlib
	ocaml-lwt-dev
	ocaml-mmap-dev
	ocaml-notty-dev
	ocaml-ocplib-endian-dev
	ocaml-uutf-dev
	ocaml-result-dev
	ocaml-seq-dev
	"
options="!check"
checkdepends="ocaml-qcheck-dev ocaml-qtest-dev"
subpackages="$pkgname-dev"
provides="ocaml-nottui=$pkgver-r$pkgrel"
source="$pkgname-$pkgver.tar.bz2::https://github.com/let-def/lwd/releases/download/v$pkgver/nottui-lwt-$pkgver.tbz
	notty-latest-git.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build \
		-p lwd,nottui,nottui-lwt,nottui-pretty \
		@install --no-buffer --verbose
}

check() {
	dune runtest --no-buffer --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml \
		lwd nottui nottui-lwt nottui-pretty

	rm -Rf "$pkgdir"/usr/doc
}

dev() {
	default_dev
	provides="ocaml-nottui-dev=$pkgver-r$pkgrel"

	cd "$pkgdir"

	local path; for path in $(find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done
}

sha512sums="
a88cfbdce6ecd280d10c34a712b685b44c712981ac85e500dab1518e513f9ac0bc02d0469184df927ab86f29e330b3439bb7eb8fb9a11f90a0a37bf46fdaa53e  ocaml-lwd-0.2.tar.bz2
4ef58722954ca93b6ea62949cb63f7942cfc67e452c3d01b6d0d7a5c22fd75107a49e20418a78462fc344c66d982023ae9f2fd97aabd27081b1093f59b706c88  notty-latest-git.patch
"
